﻿@*
    Copyright 2014 Francois Karman

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
*@
@model Quartz.WebManager.Model.JobDetail
<h1>
    @(Model.Group).@(Model.Name)
    <small>Detail about the job</small>
    <span class="pull-right">
        <a href="@Url.Action("Edit", "Job", new { name = Model.Name, group = Model.Group })" class="btn btn-default">
            <span class="glyphicon glyphicon-edit"></span> Edit
        </a>
        <a href="@Url.Action("Remove", "Job", new { name = Model.Name, group = Model.Group })" class="btn btn-default" data-confirm-message="Are you sure that you want to delete this job?">
            <span class="glyphicon glyphicon-remove"></span> Remove
        </a>
    </span>
</h1>
<div class="row">
    <div class="col-md-6">
        <p>@Model.Description</p>
        <dl class="dl-horizontal">
            @foreach (var property in Model.Definition.Properties)
            {
                <dt>@property.DisplayName</dt>
                <dd>@(Model.Properties[property.Name] == null ? (object)new HtmlString("<em>no value</em>") : Model.Properties[property.Name])</dd>
            }
        </dl>
    </div>
    <div class="col-md-6">
        <div class="well">
            <h4>Definition</h4>
            <dl class="dl-horizontal">
                <dt>JobType</dt>
                <dd>
                    @Model.Definition.DisplayName
                </dd>
                <dt>Description</dt>
                <dd>
                    @Model.Definition.Description
                </dd>
            </dl>
        </div>
    </div>
</div>
<h2>
    Triggers
    <span class="pull-right">
        <a href="@Url.Action("Add", "Trigger", new { jobGroup = @Model.Group, jobName = @Model.Name })" class="btn btn-default"><span class="glyphicon glyphicon-plus"></span> Add a trigger</a>
    </span>
</h2>
<table class="table">
    <thead>
        <tr>
            <th>Group</th>
            <th>Name</th>
            <th>Start time</th>
            <th>End time</th>
            <th>Priority</th>
            <th>Cron expression</th>
            <th></th>
        </tr>
    </thead>
    <tbody>
        @foreach (var trigger in Model.Triggers)
        {
            <tr>
                <td>
                    @trigger.Group
                </td>
                <td>
                    @trigger.Name
                </td>
                <td>
                    @trigger.StartTime
                </td>
                <td>
                    @trigger.EndTime
                </td>
                <td>
                    @trigger.Priority
                </td>
                <td>
                    @trigger.CronExpression
                </td>
                <td style="text-align: right">
                    @Html.ActionLink("Edit", "Edit", "Trigger", new { group = trigger.Group, name = trigger.Name }, new { @class = "btn btn-link" })
                    @Html.ActionLink("Remove", "Remove", "Trigger", new { group = trigger.Group, name = trigger.Name }, new { @class = "btn btn-link", dataConfirmMessage = "Are you sure that you want to delete this trigger?" })
                </td>
            </tr>
        }
    </tbody>
</table>
@section scripts
{
    <script>
        function addConfirm(tag) {
            $('[' + tag + ']').click(function (event) {
                event.preventDefault();
                var link = $(this).attr('href');
                var line = $(this).parents('tr');
                line.addClass('bg-primary');
                bootbox.confirm($(this).attr(tag), function (result) {
                    line.removeClass('bg-primary');
                    if (result) {
                        document.location.href = link;
                    }
                });
            });
        }

        $(function () {
            addConfirm('dataconfirmmessage');
            addConfirm('data-confirm-message');
        })
    </script>
}
